layui.use(['table', 'admin', 'ax','laydate', 'element'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var element = layui.element;

    //tab切换
    element.on('tab(doTabBrief)',function(data){
        console.log(data.index)
    })

    laydate.render({
        elem:'#startTime'
        ,value:new Date()
    });

    laydate.render({
        elem:'#endTime'
        ,value:new Date()
    });

    /**
     * VIEW管理
     */
    var VHxlPickDaySorterSum = {
        tableId: "vHxlPickDaySorterSumTable"
    };

    /**
     * 初始化表格的列
     */
    VHxlPickDaySorterSum.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'deliveryWarehouse', title: '仓库', width: 160},
            {field: 'sorter', title: '分拣员', width: 120},
            {field: 'postName', title: '岗位', width: 120, sort: true},
            {field: 'entryDays', title: '入职时长（天）', sort: true, width: 120, totalRowText: '合计：'},
            {field: 'pickCnt', title: '拣货数量', sort: true, width: 120, totalRow: true},
            {field: 'orderCnt', title: '拣货单数', sort: true, width: 120, totalRow: true},
            {field: 'goodsCnt', title: '商品数', sort: true, width: 120, totalRow: true},
            {field: 'goodsCntY', title: '拆零商品数', sort: true, width: 120, totalRow: true},
            {field: 'goodsCntN', title: '整件商品数', sort: true, width: 120, totalRow: true},
            {field: 'pickCntN', title: '拣货整件数量', sort: true, width: 120, totalRow: true},
            {field: 'pickCntY', title: '拣货拆零数量', sort: true, width: 120, totalRow: true},
            {field: 'pickVol', title: '拣货体积(m³)', sort: true, width: 120, totalRow: true},
            {field: 'pickTimes', title: '拣货时长(分钟)', sort: true, width: 120, totalRow: true},
            {field: 'workTimes', title: '在岗时长(分钟)', sort: true, width: 120, totalRow: true},
            {field: 'workPickTimes', title: '非拣选时长(分钟)', sort: true, width: 120, totalRow: true},
            {field: 'pickWorkRate', title: '有效时间占比', sort: true, width: 120, templet: function(d){
                    // 计算占比并显示
                    var percent = (d.pickWorkRate * 100).toFixed(2) + '%'; // 假设value是100的百分比值
                    return '<div >' + percent + '</div>';
                }},
            {field: 'pickCntTimesRate', title: '件数时效(小时)', sort: true, width: 120},
            {field: 'pickVolTimesRate', title: '体积时效(小时)', sort: true, width: 120},
            {field: 'pickCntGoodsRate', title: '件数/商品数', sort: true, width: 120},
            {field: 'pickCntVolRate', title: '件数/体积', sort: true, width: 120},
            {field: 'pickVolGoodsRate', title: '体积/商品数', sort: true, width: 120},
            {field: 'pickTimesOrderCntRate', title: '拣选时长/单数', sort: true, width: 150},
            {field: 'pickCntOrderCntRate', title: '件数/单数', sort: true, width: 120},
            {field: 'pickVolOrderCntRate', title: '体积/单数', sort: true, width: 120},
        ]];
    };

    /**
     * 点击查询按钮
     */
    VHxlPickDaySorterSum.search = function () {
        var queryData = {};
        queryData['startTime'] = $("#startTime").val();
        queryData['endTime'] = $("#endTime").val();
        queryData['deliveryWarehouse'] = $("#deliveryWarehouse").val();
        queryData['postName'] = $("#postName").val();
        table.reload(VHxlPickDaySorterSum.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };


    /**
     * 导出excel按钮
     */
    VHxlPickDaySorterSum.exportExcel = function () {
        var checkRows = table.checkStatus(VHxlPickDaySorterSum.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + VHxlPickDaySorterSum.tableId,
        url: Feng.ctxPath + '/vHxlPickDaySorterSum/listUser',
        page: true,
        limit: 120,
        limits:[120,240,360,480,1500,5000],
        height: "full-70",
        toolbar: '#toolbarfrom',
        cellMinWidth: 120,
        totalRow: true ,//开启合计行
        cols: VHxlPickDaySorterSum.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        VHxlPickDaySorterSum.search();
    });

    // 导出excel
    $('#btnExp').click(function () {
        VHxlPickDaySorterSum.exportExcel();
    });

    /** *************************** 仓库                                               **/
    laydate.render({
        elem:'#startTime1'
        ,value:new Date()
    });

    laydate.render({
        elem:'#endTime1'
        ,value:new Date()
    });

    /**
     * VIEW管理
     */
    var VHxlPickDaySorterSum1 = {
        tableId: "vHxlPickDaySorterSumTable1"
    };

    /**
     * 初始化表格的列
     */
    VHxlPickDaySorterSum1.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'deliveryWarehouse', title: '仓库', width: 160, totalRowText: '合计：'},
            {field: 'pickCntAvg', title: '日均作业件数', sort: true, width: 120},
            {field: 'pickVolAvg', title: '日均作业体积', sort: true, width: 120},
            {field: 'pickCnt', title: '拣货数量', sort: true, width: 120, totalRow: true},
            {field: 'orderCnt', title: '拣货单数', sort: true, width: 120, totalRow: true},
            {field: 'goodsCnt', title: '商品数', sort: true, width: 120, totalRow: true},
            {field: 'goodsCntY', title: '拆零商品数', sort: true, width: 120, totalRow: true},
            {field: 'goodsCntN', title: '整件商品数', sort: true, width: 120, totalRow: true},
            {field: 'pickCntN', title: '拣货整件数量', sort: true, width: 120, totalRow: true},
            {field: 'pickCntY', title: '拣货拆零数量', sort: true, width: 120, totalRow: true},
            {field: 'pickVol', title: '拣货体积(m³)', sort: true, width: 120, totalRow: true},
            {field: 'pickTimes', title: '拣货时长(分钟)', sort: true, width: 120, totalRow: true},
            {field: 'workTimes', title: '在岗时长(分钟)', sort: true, width: 120, totalRow: true},
            {field: 'workPickTimes', title: '非拣选时长(分钟)', sort: true, width: 120, totalRow: true},
            {field: 'pickWorkRate', title: '有效时间占比', sort: true, width: 120, templet: function(d){
                    // 计算占比并显示
                    var percent = (d.pickWorkRate * 100).toFixed(2) + '%'; // 假设value是100的百分比值
                    return '<div >' + percent + '</div>';
                }},
            {field: 'pickCntTimesRate', title: '件数时效(小时)', sort: true, width: 120},
            {field: 'pickVolTimesRate', title: '体积时效(小时)', sort: true, width: 120},
            {field: 'pickCntGoodsRate', title: '件数/商品数', sort: true, width: 120},
            {field: 'pickCntVolRate', title: '件数/体积', sort: true, width: 120},
            {field: 'pickVolGoodsRate', title: '体积/商品数', sort: true, width: 120},
            {field: 'pickTimesOrderCntRate', title: '拣选时长/单数', sort: true, width: 150},
            {field: 'pickCntOrderCntRate', title: '件数/单数', sort: true, width: 120},
            {field: 'pickUserCnt', title: '拣选岗人员', sort: true, width: 120},
            {field: 'pickUserVolRate', title: '拣选岗作业体积占比', sort: true, width: 150, templet: function(d){
                        // 计算占比并显示
                        var percent = (d.pickUserVolRate * 100).toFixed(2) + '%'; // 假设value是100的百分比值
                return '<div >' + percent + '</div>';
            }},
            {field: 'pickUserCntRate', title: '拣选岗作业件数占比', sort: true, width: 150, templet: function(d){
                    // 计算占比并显示
                    var percent = (d.pickUserCntRate * 100).toFixed(2) + '%'; // 假设value是100的百分比值
                    return '<div>' + percent + '</div>';
                }},
        ]];
    };

    /**
     * 点击查询按钮
     */
    VHxlPickDaySorterSum1.search = function () {
        var queryData = {};
        queryData['startTime'] = $("#startTime1").val();
        queryData['endTime'] = $("#endTime1").val();
        queryData['deliveryWarehouse'] = $("#deliveryWarehouse1").val();
        table.reload(VHxlPickDaySorterSum1.tableId, {
            where: queryData, page: {curr: 1},
            done:function () {
            }
        });
    };


    /**
     * 导出excel按钮
     */
    VHxlPickDaySorterSum1.exportExcel = function () {
        var checkRows = table.checkStatus(VHxlPickDaySorterSum1.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格
    var tableResult1 = table.render({
        elem: '#' + VHxlPickDaySorterSum1.tableId,
        url: Feng.ctxPath + '/vHxlPickDaySorterSum/listWarehouse',
        page: true,
        limit: 60,
        limits:[60,120,240,360,480,1500,5000],
        height: "full-70",
        toolbar: '#toolbarfrom',
        cellMinWidth: 120,
        totalRow: true ,//开启合计行
        cols: VHxlPickDaySorterSum1.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch1').click(function () {
        VHxlPickDaySorterSum1.search();
    });

    // 导出excel
    $('#btnExp1').click(function () {
        VHxlPickDaySorterSum1.exportExcel();
    });

});
